<?php


namespace app\common\model;


use app\common\libray\Tree;
use think\facade\Cache;
use think\Model;
use think\model\concern\SoftDelete;

class Frontmenu extends Model
{
    use SoftDelete;

    protected $autoWriteTimestamp = 'datetime';
    protected $deleteTime = 'delete_time';

    public static function getTreeFrontendMenu()
    {
        //获取导航栏
        $frontendList = Cache::get('frontmenu_list');
        if (empty($frontendList)) {
            $frontmenu = self::order('order_key asc')
                ->cache('frontmenu', 360)
                ->field('id,pid,title,link')
                ->select()
                ->toArray();
            Tree::instance()->init($frontmenu, 'pid', 'id');
            $frontendList = Tree::instance()->getTreeArray(0);
            Cache::set('frontmenu_list', $frontendList, 600);
        }
        return $frontendList;


    }
}
